package com.cspg.ssss.service;

import com.cspg.ssss.domain.ProblemFeedbackEntity;
import com.cspg.ssss.repository.ProblemFeedbackEntityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FeedbackService {
    @Autowired
    ProblemFeedbackEntityMapper problemFeedbackEntityMapper;

    public ProblemFeedbackEntity getProblemFeedbackEntity(String pid){

        HashMap<String,Object> condition = new HashMap<String,Object>();
        condition.put("problem_id",pid);

        List<ProblemFeedbackEntity> retls = problemFeedbackEntityMapper.selectFeedback(condition);

        if(retls != null && retls.size() > 0){
            return retls.get(0);
        }

        return null;
    }

    public int updateProblemFeedback(ProblemFeedbackEntity en){
        HashMap<String,Object> condition = new HashMap<String,Object>();
        condition.put("problem_id",en.getProblem_id());
        List<ProblemFeedbackEntity> retls = problemFeedbackEntityMapper.selectFeedback(condition);
        int ret = 0;
        if(retls != null && retls.size() > 0){
            en.setId(retls.get(0).getId());
            ret = problemFeedbackEntityMapper.updateFeedback(en);
        }else {
            ret = problemFeedbackEntityMapper.insertFeedback(en);
        }
        return ret;
    }

    public List<ProblemFeedbackEntity> selectModifyFeedback(Map<String,Object> condition){
        List<ProblemFeedbackEntity> retls = problemFeedbackEntityMapper.selectFeedbackWithProblem(condition);
        return retls;
    }



}
